<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <h1>注册页面</h1>
    <a href="/login.html">跳转登录页面</a>
    <br/>
    <br/>
    <form>
        <input type="text" placeholder="用户名"/>
        <input type="text" placeholder="密码"/>
        <input type="submit" value="注册">
    </form>
    <script>
        var inps = document.querySelectorAll("input");
        document.forms[0].onsubmit = function(e){
            e.preventDefault();
            // 发送ajax请求
            var xhr = new XMLHttpRequest();
            xhr.open("post","/zhuce"); //http://localhost:3000/zhuce
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            // 
            var u = inps[0].value;
            var p = inps[1].value;
            xhr.send(`username=${u}&password=${p}`)
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4){
                    console.log(xhr.responseText);
                    var res = JSON.parse(xhr.responseText);
                    console.log(res);
                }
            }
        }
    </script>
</body>
</html>